# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import os
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _

from common.storage import ImageStorage

class WxApp(models.Model):
    app_name = models.TextField(max_length=256,blank=False,verbose_name="APP 名称",help_text="")
    app_secret = models.CharField(max_length=128,blank=False,verbose_name="APP_SECRET",help_text="")
    app_id = models.CharField(max_length=128,blank=False,verbose_name="APP_ID",help_text="")
    secret_token = models.CharField(max_length=128,blank=False,verbose_name="SECRET_TOKEN",help_text="")
    encoding_aes_key = models.CharField(max_length=256,blank=False,verbose_name="ENCODING_AES_KEY",help_text="")
    splash_random = models.BooleanField(default=True,blank=False,verbose_name="随机广告",help_text="当为真(选中)时，随机播放广告")
    splash_default = models.CharField(max_length=256,default="1",blank=False,verbose_name="默认广告ID",help_text="")
    create_time = models.DateTimeField(auto_now_add=True, null=True,verbose_name="创建时间",help_text="")
    update_time = models.DateTimeField(auto_now_add=True, null=True,verbose_name="更新时间",help_text="")

    class Meta:
        verbose_name_plural = '微信公众号配置'
        verbose_name = '微信公众号配置'

class Location(models.Model):
    latitude = models.CharField(max_length=16,blank=False,verbose_name="纬度",help_text="")
    longitude = models.CharField(max_length=16,blank=False,verbose_name="经度",help_text="")
    precision = models.CharField(max_length=16,blank=False,verbose_name="精度",help_text="")
    geohash = models.CharField(default="0",max_length=16,blank=False,verbose_name="位置Hash信息",help_text="")
    create_time = models.DateTimeField(auto_now_add=True, null=True,verbose_name="创建时间",help_text="")
    update_time = models.DateTimeField(auto_now_add=True, null=True,verbose_name="更新时间",help_text="")

    class Meta:
        verbose_name_plural = '位置信息'
        verbose_name = '位置信息明细'

    def __str__(self):
        return "{0},{1},{2}".format(self.latitude,self.longitude,self.precision)

class Splashes(models.Model):
    Splash_Staus_Codes = (
        (99, _("Suspend")),
        (100, _("Normal")),
        (0, _("Not Approved Yet"))
    )

    name = models.TextField(default="无名",blank=False,verbose_name="广告名称",help_text="")
    content = models.ImageField(blank=False,verbose_name="广告图片",help_text="",upload_to= "static" + os.sep + "splashes",storage=ImageStorage())
    # splash链接 不填默认填fensihe.cn
    # #splash展示时间
    status = models.IntegerField(default=100,verbose_name="广告状态",choices=Splash_Staus_Codes,help_text="100：正常，99：停用")
    update_time = models.DateTimeField(auto_now_add=True, null=True,verbose_name="更新时间",help_text="")


    class Meta:
        verbose_name_plural = '广告Splash'
        verbose_name = '广告Splash信息明细'

